﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App1
{
    class Horse: Pieces
    {
        public override bool CheckLegalMove(int row, int col)
        {
            bool legal = false;
            // Side 1 || Side 2
            if (Math.Abs(row - _row) == 1 && Math.Abs(col - _col) == 2)
            {
                if (!Board.Square[_row, (col + _col) / 2].State)
                    legal = true;
            }
            if (Math.Abs(row - _row) == 2 && Math.Abs(col - _col) == 1)
            {
                if (!Board.Square[(row + _row) / 2, _col].State)
                    legal = true;
            }
            if (GameChess.Player[0].King.Col == GameChess.Player[1].King.Col
                && _col == GameChess.Player[1].King.Col)
            {
                int n = 0;
                if (col != _col)
                {
                    GameChess.MakeEmptySquare(_row, _col);
                    for (int i = GameChess.Player[0].King.Row + 1; i < GameChess.Player[1].King.Row; ++i)
                        if (Board.Square[i, _col].State)
                            ++n;
                    if (n == 0)
                        legal = false;
                    Board.Init(_row, _col, _name, _value, _side, true);
                }
            }
            return legal;
        }

        public override bool CheckSafeOfKing(int row, int col)
        {
            return true;
        }
    }
}
